<?php
function mysqlConnect_PHP(){
	include('../config/config.inc.php');	
	$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
	$db_select = mysql_select_db($mysql_dbname, $db);	

}
function getFriendRequests($userid, $blocked)
{
	if(empty($userid))
		return 0;
	else
	{
		mysqlConnect_PHP();
		$i = 0;
		$query = "SELECT * FROM friend_invite WHERE userid='".$userid."' AND blocked != '1';";
		$result = mysql_query($query);
		while($res = mysql_fetch_array($result))
		{
			$friends[$i] = $res['friendid'];
			$i++;
		}
		if(isset($friends))
			return $friends;
	}
}
function mysqlQuery($mysql_query, $return)
{
	mysqlConnect_PHP();
	if($mysql_query == '')
		die();
	if($return == 1)
	{
		$result =  mysql_query($mysql_query);
		$i = 0;
		$output = 0;
		while($res = mysql_fetch_array($result))
		{
			$output = $res;
		}
		return $output;
	}
	elseif($return == 0)
		mysql_query($mysql_query);
}

if(isset($_POST['notificationType']))
{
	if($_POST['notificationType'] == 1)
	{
		//Freundesanfragen
		$invites = getFriendRequests($_POST['userid'], 0);
		if (!empty($invites))
			echo count($invites);
		exit();
	}
	elseif($_POST['notificationType'] == 2)
	{
		//Ungelesene Nachrichten
		$notification_query = "SELECT COUNT(*) FROM message WHERE friendid='".$_POST['userid']."' and unread='1';";
		$var = mysqlQuery($notification_query, 1);
		$notification = $var['COUNT(*)'];
		if(!empty($notification))
			echo $notification;
		exit();
	}
}
?>